home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / Unused / HTLex.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  3.0 KB  |  141 lines

  1.  
  2. /* MODULE                            HTLex.c
  3. **        LEXICAL ANALYSOR
  4. **
  5. ** AUTHORS:
  6. **    AL    Ari Luotonen    luotonen@dxcern.cern.ch
  7. **
  8. ** HISTORY:
  9. **
  10. **
  11. ** BUGS:
  12. **
  13. **
  14. */
  15.  
  16. #include "HTAAUtil.h"
  17. #include "HTLex.h"    /* Implemented here */
  18.  
  19.  
  20. /*
  21. ** Global variables
  22. */
  23. PUBLIC char lex_buffer[40];    /* Read lexical string        */
  24. PUBLIC int lex_line = 1;    /* Line number in source file    */
  25.  
  26.  
  27. /*
  28. ** Module-wide variables
  29. */
  30. PRIVATE int lex_cnt;
  31. PRIVATE BOOL lex_template;
  32. PRIVATE LexItem lex_pushed_back = LEX_NONE;
  33. PRIVATE FILE *cache = NULL;
  34.  
  35.  
  36. PUBLIC void unlex ARGS1(LexItem, lex_item)
  37. {
  38.     lex_pushed_back = lex_item;
  39. }
  40.  
  41.  
  42. PUBLIC LexItem lex ARGS1(FILE *, fp)
  43. {
  44.     int ch;
  45.  
  46.     if (fp != cache) {    /* This cache doesn't work ok because the system  */
  47.     cache = fp;    /* often assign same FILE structure the next open */
  48.     lex_line = 1;    /* file. So, if there are syntax errors in setup  */
  49.     }            /* files it may confuse things later on.      */
  50.  
  51.     if (lex_pushed_back != LEX_NONE) {
  52.     LexItem ret = lex_pushed_back;
  53.     lex_pushed_back = LEX_NONE;
  54.     return ret;
  55.     }
  56.  
  57.     lex_cnt = 0;
  58.     lex_template = NO;
  59.  
  60.     for(;;) {
  61.     switch (ch = getc(fp)) {
  62.       case EOF:
  63.       case ' ':
  64.       case '\t':
  65.       case '\r':
  66.       case '\n':
  67.       case ':':
  68.       case ',':
  69.       case '(':
  70.       case ')':
  71.       case '@':
  72.         if (lex_cnt > 0) {
  73.         if (ch != EOF) ungetc(ch,fp);
  74.         if (lex_template) return LEX_TMPL_STR;
  75.         else          return LEX_ALPH_STR;
  76.         }
  77.         else switch(ch) {
  78.           case EOF:        return LEX_EOF;        break;
  79.           case '\n':
  80.         lex_line++;    return LEX_REC_SEP;    break;
  81.           case ':':        return LEX_FIELD_SEP;    break;
  82.           case ',':        return LEX_ITEM_SEP;    break;
  83.           case '(':        return LEX_OPEN_PAREN;    break;
  84.           case ')':        return LEX_CLOSE_PAREN;    break;
  85.           case '@':        return LEX_AT_SIGN;    break;
  86.           default:    ;    /* Leading white space ignored (SP,TAB,CR) */
  87.         }
  88.         break;
  89.       default:
  90.         lex_buffer[lex_cnt++] = ch;
  91.         lex_buffer[lex_cnt] = (char)0;
  92.         if ('*' == ch) lex_template = YES;
  93.     } /* switch ch */
  94.     } /* forever */
  95. }
  96.  
  97.  
  98. PUBLIC char *lex_verbose ARGS1(LexItem, lex_item)
  99. {
  100.     static char msg[100];
  101.  
  102.     switch (lex_item) {
  103.       case LEX_NONE:        /* Internally used    */
  104.     return "NO-LEX-ITEM";
  105.     break;
  106.       case LEX_EOF:        /* End of file        */
  107.     return "end-of-file";
  108.     break;
  109.       case LEX_REC_SEP:        /* Record separator    */
  110.     return "record separator (newline)";
  111.     break;
  112.       case LEX_FIELD_SEP:    /* Field separator    */
  113.     return "field separator ':'";
  114.     break;
  115.       case LEX_ITEM_SEP:    /* List item separator    */
  116.     return "item separator ','";
  117.     break;
  118.       case LEX_OPEN_PAREN:    /* Group start tag    */
  119.     return "'('";
  120.     break;
  121.       case LEX_CLOSE_PAREN:    /* Group end tag    */
  122.     return "')'";
  123.     break;
  124.       case LEX_AT_SIGN:        /* Address qualifier    */
  125.     return "address qualifier '@'";
  126.     break;
  127.       case LEX_ALPH_STR:    /* Alphanumeric string    */
  128.     sprintf(msg, "alphanumeric string '%s'", lex_buffer);
  129.     return msg;
  130.     break;
  131.       case LEX_TMPL_STR:    /* Template string    */
  132.     sprintf(msg, "template string '%s'", lex_buffer);
  133.     return msg;
  134.     break;
  135.       default:
  136.     return "UNKNOWN-LEX-ITEM";
  137.     break;
  138.     }
  139. }
  140.  
  141.